﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using HighDivePrinter.View;
using HighDivePrinter.Properties;
using HighDivePrinter.Presenter;
using HighDivePrinter.Model;



namespace HighDivePrinter
{
    public partial class FormMain : Form, IFormMain
    {
        private int _row = -1;
        public FormMain()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Event Click on button "New Diver"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _buttonNewDiver_Click(object sender, EventArgs e)
        {
            if (this.EventNewDiver != null)
                this.EventNewDiver();
        }

        private void _buttonSaveToFile_Click(object sender, EventArgs e)
        {
            if (this.EventSaveToFile != null)
                this.EventSaveToFile();
        }

        private void _buttonReadFromFile_Click(object sender, EventArgs e)
        {
            if (this.EventReadFromFile != null)
                this.EventReadFromFile();
        }

        private void _buttonDeleteDiver_Click(object sender, EventArgs e)
        {
            //this._row = this._dataGridView.Rows.
            if (this._row != -1)
                if (this.EventDeleteDiver != null)
                    this.EventDeleteDiver(this._row);
            this._row = 1;

        }

        private void _dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            this._row = e.RowIndex;
        }

        #region IFormMain Members

        //Diver Class members
        void IFormMain.SetDiverList(BindingList<Diver> Divers)
        {
            this._dataGridView.DataSource = Divers;
        }

        public event DelegateNewDiver EventNewDiver = null;
        public event DelegateDeleteDiver EventDeleteDiver = null;
        public event DelegateSaveToFile EventSaveToFile = null;
        public event DelegateReadFromFile EventReadFromFile = null;

        //Dive class memeber 
        void IFormMain.SetDiveList(BindingList<Dive> Dives)
        {
            this.dataGridView1.DataSource = Dives;
        }

        public event DelegateAddToList EventAddToList = null;
        public event DelegateRemoveFromList EventRemoveFromList = null;
        public event DelegateSaveList EventSaveList = null;
        public event DelegateReadList EventReadList = null;


        #endregion

        #region Printing

        /// <summary>
        /// Händelsemetod för att hantera EVENT ButtonClick
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _buttonPrint_Click(object sender, EventArgs e)
        {
            PrintDocumentDive pdc = new PrintDocumentDive((BindingList<Diver>)this._dataGridView.DataSource, (BindingList<Dive>)this.dataGridView1.DataSource);
            pdc.MyPrint();
        }

        #endregion

        private void FormMain_Load(object sender, EventArgs e)
        {

        }

        private void DivepictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void _dataGridView_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            //diver view
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //dive view
        }

        private void AddListbutton4_Click(object sender, EventArgs e)
        {
            if (this.EventAddToList != null)
                this.EventAddToList();
        }

        private void SaveListbutton2_Click(object sender, EventArgs e)
        {
            if (this.EventSaveList != null)
                this.EventSaveList();
        }

        private void DiveListbutton1_Click(object sender, EventArgs e)
        {
            if (this.EventReadList != null)
                this.EventReadList();
        }

        private void DeleteFromListbutton3_Click(object sender, EventArgs e)
        {
            //this._row = this._dataGridView.Rows.
            if (this._row != -1)
                if (this.EventRemoveFromList != null)
                    this.EventRemoveFromList(this._row);
            this._row = 1;
        }

        private void DiveListpictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void PrintDiverListbutton1_Click(object sender, EventArgs e)
        {
            PrintDocumentDiverList pdc = new PrintDocumentDiverList((BindingList<Dive>)this.dataGridView1.DataSource);
            pdc.MyPrint();
        }


    }


}
